home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 33.3 KB | 1,199 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UTEDocument.cp
- // Copyright © 1990-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UTEDOCUMENT__
- #include "UTEDocument.h"
- #endif
-
- // MacApp
-
- #ifndef __GEOMETRY__
- #include "Geometry.h"
- #endif
-
- #ifndef __UAPPLICATION__
- #include "UApplication.h"
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UFILE__
- #include "UFile.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #if qPowerTalk
- #ifndef __UMAILER__
- #include "UMailer.h"
- #endif
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UPATCH__
- #include "UPatch.h"
- #endif
-
- #if UsingDemoTextPrinting
- # ifndef __UPRINTING__
- # include "UPrinting.h"
- # endif
- #endif
-
- #ifndef __UTECOMMANDS__
- #include "UTECommands.h"
- #endif
-
- #ifndef __UTEVIEW__
- #include "UTEView.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #if qPowerTalk
- #ifndef __OCESTANDARDMAIL__
- #include <OCEStandardMail.h>
- #endif
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __PICKER__
- #include <Picker.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // static data members
- //----------------------------------------------------------------------------------------
- TextSpecs TTEDocument::gDefaultSpecs;
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
-
-
- //----------------------------------------------------------------------------------------
- // InitUTEDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment TEInit
-
- void InitUTEDocument()
- {
- TTEDocument::gDefaultSpecs.theTextFont = "Geneva";
- TTEDocument::gDefaultSpecs.theTextFace = 0;
- TTEDocument::gDefaultSpecs.theTextSize = 12;
- TTEDocument::gDefaultSpecs.theTextColor = gRGBBlack;
- TTEDocument::gDefaultSpecs.theJustification = teFlushDefault;
- TTEDocument::gDefaultSpecs.theBackColor = gRGBWhite;
- } // InitUTEDocument
-
-
- //========================================================================================
- // CLASS TTEDocument
- //========================================================================================
- #undef Inherited
-
- #if qPowerTalk
- #define Inherited TMailableDocument
- #else
- #define Inherited TFileBasedDocument
- #endif
-
- #pragma segment TEDocOpen
- MA_DEFINE_CLASS_M1(TTEDocument,Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::TTEDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocOpen
-
- TTEDocument::TTEDocument()
- {
- fDocText = NULL;
- fElements = NULL;
- fStyles = NULL;
- fTEView = NULL;
- fTextSpecs = gDefaultSpecs;
- fViewResourceID = kDefaultViewID;
- #if qPowerTalk
- fSendFormats = kSMPNativeMask + kSMPStandardInterchangeMask;
- #endif
- } // TTEDocument::TTEDocument
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::ITEDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocOpen
-
- void TTEDocument::ITEDocument(TFile* itsFile,
- const OSType itsScrapType,
- ResNumber itsViewResourceID)
- {
- #if qPowerTalk
- this->IMailableDocument(itsFile, itsScrapType);
- #else
- this->IFileBasedDocument(itsFile, itsScrapType);
- #endif
-
-
-
- FailInfo fi;
- Try(fi)
- {
- fDocText = NewPermHandle(0);
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
-
- fViewResourceID = itsViewResourceID;
- } // TTEDocument::ITEDocument
-
- //----------------------------------------------------------------------------------------
- // TTEDocument destructor
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocClose
-
- TTEDocument::~TTEDocument()
- {
- fDocText = DisposeIfHandle(fDocText);
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::ChangeBackColor:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocNonRes
-
- void TTEDocument::ChangeBackColor(const CRGBColor& newColor)
- {
- GrafPtr oldPort;
- TView * itsRootView;
-
- //??? Is this right? Should we set the background color even if
- // the view isn't in a window yet?
- GetPort(&oldPort);
- SetPort((*fTEView->fHTE)->inPort);
- RGBBackColor(newColor);
- itsRootView = fTEView->GetRootView();
- if (itsRootView)
- itsRootView->ForceRedraw();
- SetPort(oldPort);
- } // TTEDocument::ChangeBackColor
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoInitialState:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocOpen
-
- void TTEDocument::DoInitialState() // Override
- {
- fTextSpecs = gDefaultSpecs;
- } // TTEDocument::DoInitialState
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoMakeViews:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocOpen
-
- void TTEDocument::DoMakeViews(Boolean /*forPrinting*/ ) // Override
-
- {
- TWindow* aWindow;
-
- FailNIL(aWindow = gViewServer->NewTemplateWindow(fViewResourceID, this));
-
- fTEView = (TTEView*) aWindow->FindSubView('TEVW'); // Must cast because FindSubView returns TView
-
- #if UsingDemoTextPrinting
- TStdPrintHandler* aHandler = new TStdPrintHandler;
- aHandler->IStdPrintHandler(this, // its document
- fTEView, // its view
- kFixedSize, // horzontal page size is fixed
- !kFixedSize); // vertical page size is variable (could be
- // set to true on non-style TE systems)
- #endif
-
- this->ShowReverted();
- } // TTEDocument::DoMakeViews
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoJustChange:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocSelCommand
-
- void TTEDocument::DoJustChange(CommandNumber aCommandNumber)
- {
- short newJust;
- TJustCommand * aJustChange;
-
- switch (aCommandNumber)
- {
- case cJustSystem:
- newJust = teFlushDefault;
- break;
-
- case cJustForceLeft:
- newJust = teFlushLeft;
- break;
-
- case cJustCenter:
- newJust = teCenter;
- break;
-
- case cJustRight:
- newJust = teFlushRight;
- break;
- };
- aJustChange = new TJustCommand;
- aJustChange->IJustCommand(fTEView, newJust);
- fTextSpecs.theJustification = newJust;
- this->PostCommand(aJustChange);
- } // TTEDocument::DoJustChange
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoStyleChange:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocSelCommand
-
- void TTEDocument::DoStyleChange(CommandNumber aCommandNumber)
- {
- TextStyle newStyle;
-
- switch (aCommandNumber)
- {
- case cBold:
- newStyle.tsFace = bold;
- break;
-
- case cItalic:
- newStyle.tsFace = italic;
- break;
-
- case cUnderline:
- newStyle.tsFace = underline;
- break;
-
- case cOutline:
- newStyle.tsFace = outline;
- break;
-
- case cShadow:
- newStyle.tsFace = shadow;
- break;
-
- case cCondense:
- newStyle.tsFace = condense;
- break;
-
- case cExtend:
- newStyle.tsFace = extend;
- break;
- }
- if ((newStyle.tsFace * fTextSpecs.theTextFace) == newStyle.tsFace)
- fTextSpecs.theTextFace -= newStyle.tsFace;
- else
- fTextSpecs.theTextFace += newStyle.tsFace;
- this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cStyleChange, doFace + doToggle));
- } // TTEDocument::DoStyleChange
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoColTextChange:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocSelCommand
-
- void TTEDocument::DoColTextChange()
- {
- TextStyle newStyle;
- CRGBColor aColor;
- CStr255 promptString;
-
- aColor = fTextSpecs.theTextColor;
- GetIndString(promptString, kPromptsRsrcID, kColTextPrompt);
- if (GetColor(kBestSystemLocation, promptString, aColor, ((CRGBColor &) newStyle.tsColor)))
- {
- fTextSpecs.theTextColor = newStyle.tsColor;
- this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cColorChange, doColor + doToggle));
- }
- } // TTEDocument::DoColTextChange
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoColBackChange:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocSelCommand
-
- void TTEDocument::DoColBackChange()
- {
- TextStyle newStyle;
- CRGBColor aColor;
- CStr255 promptString;
-
- aColor = fTextSpecs.theBackColor;
- GetIndString(promptString, kPromptsRsrcID, kColBackPrompt);
- if (GetColor(kBestSystemLocation, promptString, aColor, ((CRGBColor &) newStyle.tsColor)))
- {
- fTextSpecs.theBackColor = newStyle.tsColor;
- this->ChangeBackColor(newStyle.tsColor);
- }
- } // TTEDocument::DoColBackChange
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::InstallChangedDeterminer:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocSelCommand
-
- void TTEDocument::InstallChangedDeterminer(VHSelect vhs,
- SizeDeterminer sd)
- {
- if (sd != fTEView->fSizeDeterminer[vhs])
- {
- fTEView->fSizeDeterminer[vhs] = sd;
-
- // If we changed the horizontal size determiner,
- // we must ask the TTEView to recompute the TE rectangles.
- if (vhs == hSel)
- switch (sd)
- {
- case sizeSuperView:
- {
- VRect itsFrame(fTEView->GetFrame());
- fTEView->SuperViewChangedFrame(itsFrame, itsFrame, TRUE);// Don't care about deltas
- break;
- }
-
- case sizePage:
- fTEView->DoPagination();
- break;
- }
-
- fTEView->AdjustFrame();
- fTEView->ForceRedraw();
- }
- } // TTEDocument::InstallChangedDeterminer
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoWidthChange:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocSelCommand
-
- void TTEDocument::DoWidthChange(CommandNumber aCommandNumber)
- {
- SizeDeterminer sd;
-
- if (aCommandNumber == cWidthSuperView)
- sd = sizeSuperView;
- else if (aCommandNumber == cWidthOnePage)
- sd = sizePage;
- else
- sd = sizeFixed;
-
- // NB: The following is not undoable in the
- // current version
- this->InstallChangedDeterminer(hSel, sd);
- } // TTEDocument::DoWidthChange
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoHeightChange:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocSelCommand
-
- void TTEDocument::DoHeightChange(CommandNumber aCommandNumber)
- {
- SizeDeterminer sd;
-
- switch (aCommandNumber)
- {
- case cHeightSuperView:
- sd = sizeSuperView;
- break;
-
- case cHeightPages:
- sd = sizeFillPages;
- break;
-
- case cHeightText:
- sd = sizeVariable;
- break;
-
- case cHeightConst:
- sd = sizeFixed;
- break;
- }
-
- // NB: The following is not undoable in the
- // current version
- this->InstallChangedDeterminer(vSel, sd);
- } // TTEDocument::DoHeightChange
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocSelCommand
-
- void TTEDocument::DoMenuCommand(CommandNumber aCommandNumber)// override
- {
- CStr255 aName;
- short menu;
- short item;
- TextStyle newStyle;
-
- CommandToMenuItem(aCommandNumber, menu, item);
-
- if (menu == mFont)
- {
- GetMenuItemText(MAGetMenu(menu), item, aName);
- GetFNum(aName, &(newStyle.tsFont));
- fTextSpecs.theTextFont = aName;
- this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cFontChange, doFont + doToggle));
- }
- else if ((aCommandNumber > cSizeBase) && (aCommandNumber <= cSizeMax))
- {
- newStyle.tsSize = (short)(aCommandNumber - cSizeBase);
- fTextSpecs.theTextSize = newStyle.tsSize;
- this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cSizeChange, doSize + doToggle));
- }
- else
- switch (aCommandNumber)
- {
- case cSizeOther:
- // as yet unsupported
- break;
-
- case cSizeGrow:
- case cSizeShrink:
- if (aCommandNumber == cSizeGrow)
- {
- newStyle.tsSize = kRelSizeAmount;
- fTextSpecs.theTextSize += kRelSizeAmount;
- }
- else
- {
- newStyle.tsSize = -kRelSizeAmount;
- fTextSpecs.theTextSize -= kRelSizeAmount;
- }
- this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cSizeChange, doSize + addSize + doToggle));
- break;
-
- case cJustForceLeft:
- case cJustCenter:
- case cJustRight:
- case cJustSystem:
- this->DoJustChange(aCommandNumber);
- break;
-
- case cPlainText:
- newStyle.tsFace = 0;
- fTextSpecs.theTextFace = 0;
- this->PostCommand(fTEView->DoMakeStyleCommand(newStyle, cStyleChange, doFace));
- break;
-
- case cBold:
- case cItalic:
- case cUnderline:
- case cOutline:
- case cShadow:
- case cCondense:
- case cExtend:
- this->DoStyleChange(aCommandNumber);
- break;
-
- case cColorText:
- this->DoColTextChange();
- break;
-
- case cColorBackground:
- this->DoColBackChange();
- break;
-
- case cWidthSuperView:
- case cWidthView:
- case cWidthOnePage:
- this->DoWidthChange(aCommandNumber);
- break;
-
- case cHeightSuperView:
- case cHeightPages:
- case cHeightText:
- case cHeightConst:
- this->DoHeightChange(aCommandNumber);
- break;
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- } // TTEDocument::DoMenuCommand
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoNeedDiskSpace:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocWriteFile
-
- void TTEDocument::DoNeedDiskSpace(TFile* itsFile,
- long& dataForkBytes,
- long& rsrcForkBytes)// override
- {
-
- dataForkBytes += GetHandleSize(fDocText);
-
- if ((fTEView->fStyleType == kWithStyle) && (fTEView->fHTE))
- {
- TEStyleHandle styles;
- STHandle elements;
- fTEView->ExtractStyles(styles, elements);
- rsrcForkBytes += GetHandleSize((Handle)styles) + kRsrcTypeOverhead + kRsrcOverhead + GetHandleSize((Handle)elements) + kRsrcTypeOverhead + kRsrcOverhead;
- }
-
- rsrcForkBytes += sizeof(TextSpecs) + kRsrcTypeOverhead + kRsrcOverhead;
-
- // Get resource file overhead
- Inherited::DoNeedDiskSpace(itsFile, dataForkBytes, rsrcForkBytes);
- } // TTEDocument::DoNeedDiskSpace
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoRead:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocReadFile
-
- void TTEDocument::DoRead(TFile* aFile,
- Boolean forPrinting) // override
- {
- long numChars;
- TextSpecsHdl hTextSpecs;
- Boolean oldPermAllocation;
- FailInfo fi;
-
- FailOSErr(aFile->GetDataLength(numChars)); // Read in the text
-
- if (numChars > kUnlimited) // The file may have been created by…
- {
- // …someone else - limit it to 32K!
- gApplication->ShowError(0, messageAlert + kFileTooBig);
- numChars = kUnlimited;
- }
-
- SetPermHandleSize(fDocText, numChars);
- SignedByte savedState = LockHandleHigh(fDocText); // lock handle before deref
-
- Try(fi)
- {
- FailOSErr(aFile->ReadData(*fDocText, numChars));
-
- HSetState(fDocText, savedState); // restore state of handle
- fi.Success();
- }
- else
- {
- HSetState(fDocText, savedState); // restore state of handle
- fi.ReSignal();
- }
-
- // Read in the TEStyleRec
- fStyles = (TEStyleHandle)Get1Resource(kTextStyleRsrcType, kStylesRsrcID);
- if (fStyles)
- DetachResource((Handle)fStyles);
-
- // Read in the STElement array from permanent allocation
- oldPermAllocation = PermAllocation(TRUE);
- fElements = (STHandle)(Get1Resource(kTextStyleRsrcType, kElementsRsrcID));
- PermAllocation(oldPermAllocation);
-
- if (fElements)
- DetachResource((Handle)fElements);
-
- // Read the text specs resource
- hTextSpecs = (TextSpecsHdl)Get1Resource(kTextSpecsRsrcType, kTextSpecsRsrcID);
- if (hTextSpecs)
- {
- fTextSpecs = **hTextSpecs;
- ReleaseResource((Handle)hTextSpecs);
- }
- else
- this->DoInitialState();
-
- Inherited::DoRead(aFile, forPrinting);
- } // TTEDocument::DoRead
-
- #if qPowerTalk
- //----------------------------------------------------------------------------------------
- // TTEDocument::AddStandardMailContent:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocRes
-
- void TTEDocument::AddStandardMailContent(Boolean& okToSend)
- {
- WindowRef theWindow = fTEView->GetGrafPort();
- Boolean appendFlag = FALSE;
- Handle theText = fTEView->ExtractText();
- SignedByte wasTextState = LockHandleHigh(theText);
- Ptr buffer = *theText;
- unsigned long bufferSize = GetHandleSize(theText);
- StScrpHandle theStyles = (StScrpHandle)NewHandle(10);
- fTEView->GivePasteData((Handle)theStyles, 'styl');
- SignedByte wasStyleState = LockHandleHigh((Handle)theStyles);
- Boolean startNewScript = TRUE;
- short scriptID = smRoman;
- FailOSErr(SMPAddContent(theWindow, kMailStyledTextSegmentType, appendFlag,
- buffer, bufferSize, *theStyles, startNewScript, scriptID));
- HSetState(theText, wasTextState);
- HSetState((Handle)theStyles, wasStyleState);
- DisposeIfHandle((Handle)theStyles);
- okToSend = TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::ReadStandardMailContent:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocRes
-
- Boolean TTEDocument::ReadStandardMailContent()
- {
- Boolean readContent = FALSE;
- const unsigned long kBufferSize = 10000;
- MailSegmentMask segmentTypeMask = kMailStyledTextSegmentMask;
- Handle buffer = NewHandle(kBufferSize);
- FailNIL(buffer);
-
- const short kNumStyles = 200;
- const long kStyleBufferSize = (sizeof(ScrpSTElement) * kNumStyles) + 4;
- StScrpHandle theStyles = (StScrpHandle)NewHandleClear(kStyleBufferSize);
- FailNIL(theStyles);
-
- Boolean endOfContent = FALSE;
- OSErr err = noErr;
- Boolean allContentExtracted = TRUE;
-
- while ((err == noErr) && !endOfContent)
- {
- // skip past empty text segments
- ScriptCode script = 0;
- unsigned long dataSize = 0;
- long segmentLength = 0;
- long segmentID = 0;
- Boolean endOfScript = FALSE;
- Boolean endOfSegment = FALSE;
- MailSegmentType segmentType;
-
- endOfContent = FALSE;
-
-
- unsigned long bufferSize = kBufferSize;
- SetHandleSize(buffer, bufferSize);
- SetHandleSize((Handle)theStyles, kStyleBufferSize);
- (**theStyles).scrpNStyles = kNumStyles;
- SignedByte wasStylesState = LockHandle((Handle)theStyles);
- SignedByte wasBufferState = LockHandle(buffer);
- err = SMPReadContent(fLetter->GetMailerWindowRef(), segmentTypeMask,
- *buffer, bufferSize, &dataSize, *theStyles, &script,
- &segmentType, &endOfScript, &endOfSegment, &endOfContent,
- &segmentLength, &segmentID);
-
- if(allContentExtracted && (dataSize > 0) && !endOfContent)
- allContentExtracted = FALSE;
-
- if ((err == noErr) && (dataSize > 0))
- {
- HSetState(buffer, wasBufferState);
- HSetState((Handle)theStyles, wasStylesState);
- SetHandleSize(buffer, dataSize);
- unsigned long textSize = dataSize;
- dataSize = (sizeof(ScrpSTElement) * (**theStyles).scrpNStyles) + 4;
- SetHandleSize((Handle)theStyles, dataSize);
- TEStyleInsert(*buffer, textSize, (StScrpHandle)theStyles, fTEView->fHTE);
- fTEView->SynchView(FALSE);
- readContent = TRUE;
- }
- }
-
- DisposeIfHandle(buffer);
- DisposeIfHandle((Handle)theStyles);
-
- if(!allContentExtracted)
- {
- MacAppAlert(kContentNotExtracted, NULL);
- }
-
- return readContent;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::ReadNativeMailContent:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocRes
-
- Boolean TTEDocument::ReadNativeMailContent()
- {
- Boolean readContent = TMailableDocument::ReadNativeMailContent();
-
- // fStyles and fElements are native to DemoText (see TTEDocument::DoRead)
- // so they can be used as a valid check for native content.
- if (fDocText && fStyles && fElements)
- {
- this->ShowReverted();
- readContent = TRUE;
- }
- return readContent;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::ReadNativeMailContent:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocRes
-
- Boolean TTEDocument::ReadSnapshotMailContent()
- {
- Boolean readContent = FALSE;
-
- OCECreatorType theBlockType;
- theBlockType.msgCreator = 'apml';
- theBlockType.msgType = 'imag';
- unsigned long blockIndex = 1;
- const unsigned long theBufferSize = 10000;
- Handle buffer = NewHandle(theBufferSize);
- FailNIL(buffer);
-
- unsigned long dataOffset = 0;
- unsigned long dataSize = 0;
- Boolean endOfBlock = FALSE;
- unsigned long dataRemaining;
- OSErr err = noErr;
-
- unsigned long bufferSize = theBufferSize;
- SetHandleSize(buffer, bufferSize);
-
-
- err = SMPReadBlock(fLetter->GetMailerWindowRef(),&theBlockType,blockIndex,*buffer,bufferSize,
- dataOffset,&dataSize,&endOfBlock,&dataRemaining);
- if(err == noErr && dataSize > 0)
- {
- MacAppAlert(kSnapshotNotExtracted, NULL);
- readContent = TRUE;
- }
-
- return readContent;
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::SetReplyContents:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocRes
-
- void TTEDocument::SetReplyContents(TDocument* replyToDoc)
- {
- DisposeIfHandle(fDocText);
- fDocText = ((TTEDocument*)replyToDoc)->fDocText;
- FailOSErr(HandToHand(&fDocText));
-
- DisposeIfHandle((Handle)fElements);
- fElements = ((TTEDocument*)replyToDoc)->fElements;
- if (fElements != NULL)
- FailOSErr(HandToHand((Handle*)&fElements));
-
- DisposeIfHandle((Handle)fStyles);
- fStyles = ((TTEDocument*)replyToDoc)->fStyles;
- if (fStyles != NULL)
- FailOSErr(HandToHand((Handle*)&fStyles));
-
- ShowReverted();
-
- if (fTEView->Focus())
- {
- (*fTEView->fHTE)->selStart = 0;
- (*fTEView->fHTE)->selEnd = 0;
-
- CStr255 replySpacer;
- GetIndString(replySpacer, kPromptsRsrcID, kReplySpacer);
- TextStyle newStyle;
- newStyle.tsFace = 0;
- TESetStyle(doFace,&newStyle,FALSE,fTEView->fHTE);
- TEInsert((Ptr)&replySpacer.fStr[1], replySpacer.Length(),fTEView->fHTE);
-
- (*fTEView->fHTE)->selStart = 0;
- (*fTEView->fHTE)->selEnd = 0;
- fTEView->SynchView(FALSE);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::ImageDocumentForLetter:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocRes
-
- void TTEDocument::ImageDocumentForLetter(Boolean /* inColor */)
- {
- // ••• Need to fill this in •••
- }
-
- #endif // qPowerTalk
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocRes
-
- void TTEDocument::DoSetupMenus() // override
- {
- Boolean checkPlain;
- Boolean checkFont;
- Boolean specChange;
- short just;
- short aMode;
- Style aFace;
- SizeDeterminer sd;
- MenuRef aMenuRef;
- CStr255 aName;
- TextStyle aStyle;
- short theFont;
- short startOfSelection;
- short endOfSelection;
- short nItems;
-
- Inherited::DoSetupMenus();
-
- startOfSelection = (*fTEView->fHTE)->selStart;
- endOfSelection = (*fTEView->fHTE)->selEnd;
-
- aMode = doFace;
- checkPlain = fTEView->ContinuousStyle(startOfSelection, endOfSelection, aMode, aStyle) && (aStyle.tsFace == 0);
-
- aMode = doAll;
- aStyle.tsFace = bold | italic | underline | outline | shadow | extend | condense;
-
- specChange = fTEView->ContinuousStyle(startOfSelection, endOfSelection, aMode, aStyle);
- checkFont = ((aMode & doFont) != 0);
-
- aMenuRef = MAGetMenu(mFont);
- if (aMenuRef)
- {
- // If specs have changed && EITHER an old-style record || the font's continuous - Ed.
- specChange = (fTEView->fSpecsChanged && checkFont);
-
- GetFontName(aStyle.tsFont, aName); // Get real font number in case tsFont is
- GetFNum(aName, &theFont); // …the system or application font.
- nItems = CountMItems(aMenuRef);
- for (short item = 1; item <= nItems; ++item)
- {
- // There can be more than 31 menu entries with scrolling menus, but trying to enable
- // an item with number > 31 is bad news. If the menu itself is enabled (which it
- // will be in MacApp if any of the first 31 items is enabled), then the extras
- // will always be enabled.
- if (item <= 31)
- EnableItem(aMenuRef, item);
- if (checkFont)
- {
- short fnt;
-
- GetMenuItemText(aMenuRef, item, aName);
- GetFNum(aName, &fnt);
- CheckItem(aMenuRef, item, (fnt == theFont));
- }
- }
- }
-
- sd = fTEView->fSizeDeterminer[hSel]; // Enable size determiner related menu items
- EnableCheck(cWidthSuperView, TRUE, (sd == sizeSuperView));
- EnableCheck(cWidthOnePage, TRUE, (sd == sizePage));
- EnableCheck(cWidthView, TRUE, (sd == sizeFixed));
-
- sd = fTEView->fSizeDeterminer[vSel];
- EnableCheck(cHeightSuperView, TRUE, (sd == sizeSuperView));
- EnableCheck(cHeightPages, TRUE, (sd == sizeFillPages));
- EnableCheck(cHeightText, TRUE, (sd == sizeVariable));
- EnableCheck(cHeightConst, TRUE, (sd == sizeFixed));
-
- just = fTEView->fJustification; // Enable justification related menu items
- EnableCheck(cJustSystem, TRUE, (just == teFlushDefault));
- EnableCheck(cJustForceLeft, TRUE, (just == teFlushLeft));
- EnableCheck(cJustCenter, TRUE, (just == teCenter));
- EnableCheck(cJustRight, TRUE, (just == teFlushRight));
-
- Enable(cStyle, TRUE); // Enable sub-menus
- Enable(cSize, TRUE);
- Enable(cFont, TRUE);
- Enable(cColor, (qNeedsColorQD || HasColorQD()));
-
- aFace = aStyle.tsFace;
- EnableCheck(cPlainText, TRUE, checkPlain); // Enable normal Style menu items
- EnableCheck(cBold, TRUE, bold & aFace);
- EnableCheck(cItalic, TRUE, italic & aFace);
- EnableCheck(cUnderline, TRUE, underline & aFace);
- EnableCheck(cOutline, TRUE, outline & aFace);
- EnableCheck(cShadow, TRUE, shadow & aFace);
- EnableCheck(cCondense, TRUE, condense & aFace);
- EnableCheck(cExtend, TRUE, extend & aFace);
-
- for (CommandNumber c = cSizeMin; c <= cSizeMax; ++c)
- {
- Boolean checkSize;
-
- if (!(aMode & doSize))
- checkSize = FALSE;
- else
- checkSize = ((c - cSizeBase) == aStyle.tsSize);
-
- EnableCheck(c, TRUE, checkSize);
- if (fTEView->fSpecsChanged)
- {
- // if it _is_ styled and font is continuous
- // …and the size is a real one
- if ((aMode & doFont) && RealFont(aStyle.tsFont, (short) (c - cSizeBase)))
- aFace = outline; // …then we outline it
- else
- aFace = 0;
- SetStyle(c, aFace);
- }
- }
-
- Enable(cSizeGrow, TRUE);
- Enable(cSizeShrink, TRUE);
-
- Enable(cColorText, (qNeedsColorQD || HasColorQD()));
- Enable(cColorBackground, (qNeedsColorQD || HasColorQD()));
-
- fTEView->fSpecsChanged = FALSE;
- } // TTEDocument::DoSetupMenus
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::DoWrite:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocWriteFile
-
- void TTEDocument::DoWrite(TFile* aFile,
- Boolean makingCopy) // override
- {
- long numChars;
- TextSpecsHdl hTextSpecs;
-
- // Write out the text
- numChars = GetHandleSize(fDocText);
- SignedByte savedState = LockHandleHigh(fDocText); // lock handle before deref
- FailOSErr(aFile->WriteData(*fDocText, numChars));
- HSetState(fDocText, savedState); // restore state of handle
-
- if (fTEView->fStyleType == kWithStyle)
- {
- TEStyleHandle styles;
- STHandle elements;
-
- fTEView->ExtractStyles(styles, elements);
- PermHandToHand((Handle &) styles);
- AddResource((Handle)styles, kTextStyleRsrcType, kStylesRsrcID, gEmptyString);
- FailResError(); // !!! need a failure handler
- PermHandToHand((Handle &) elements);
- AddResource((Handle)elements, kTextStyleRsrcType, kElementsRsrcID, gEmptyString);
- FailResError(); // !!! need a failure handler
- }
-
- // Write the text specification resource, after converting it to a handle
- hTextSpecs = (TextSpecsHdl)NewPermHandle(sizeof(TextSpecs));
- **hTextSpecs = fTextSpecs;
- AddResource((Handle)hTextSpecs, kTextSpecsRsrcType, kTextSpecsRsrcID, gEmptyString);
- FailResError(); // !!! need a failure handler
-
- Inherited::DoWrite(aFile, makingCopy);
- } // TTEDocument::DoWrite
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::FreeData:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocClose
-
- void TTEDocument::FreeData() // override
- {
- SetPermHandleSize(fDocText, 0);
- } // TTEDocument::FreeData
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::SetSpecStyle:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocRes
-
- void TTEDocument::SetSpecStyle()
- {
- short theFont;
- TextStyle theTS;
- CStr255 aStr255;
-
- aStr255 = fTextSpecs.theTextFont;
- GetFNum(aStr255, &theFont);
- CRGBColor theTextColor = fTextSpecs.theTextColor;
- SetTextStyle(theTS, theFont, fTextSpecs.theTextFace, fTextSpecs.theTextSize, theTextColor);
- fTEView->SetOneStyle(0, 0, doAll, theTS, kDontRedraw);
- } // TTEDocument::SetSpecStyle
-
- //----------------------------------------------------------------------------------------
- // TTEDocument::ShowReverted:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocReadFile
-
- void TTEDocument::ShowReverted() // override
- {
- CRGBColor aColor;
-
- fTEView->StuffText(fDocText); // put in the text
- TESetSelect(0, 0, fTEView->fHTE);
- if (fStyles && fElements) // If we're able, stuff style info
- fTEView->StuffStyles(fStyles, fElements);
- else
- this->SetSpecStyle();
-
- if (qNeedsColorQD || HasColorQD())
- {
- aColor = fTextSpecs.theBackColor;
- this->ChangeBackColor(aColor);
- }
- fTEView->SetJustification(fTextSpecs.theJustification, kDontRedraw);
- Inherited::ShowReverted();
- } // TTEDocument::ShowReverted
-
-
- //========================================================================================
- // CLASS TJustCommand
- //========================================================================================
-
-
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment TEDocSelCommand
- MA_DEFINE_CLASS_M1(TJustCommand,Inherited);
-
-
- //----------------------------------------------------------------------------------------
- // TJustCommand::TJustCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocSelCommand
- TJustCommand::TJustCommand()
- {
- fOldJust = teFlushDefault;
- fNewJust = teFlushDefault;
- fTEView = NULL;
- } // TJustCommand::TJustCommand
-
- //----------------------------------------------------------------------------------------
- // TJustCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TJustCommand::~TJustCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TJustCommand::IJustCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocSelCommand
-
- void TJustCommand::IJustCommand(TTEView* itsTEView,
- short itsNewJust)
- {
- TCommandHandler* theContext = NULL;
-
- if (itsTEView)
- theContext = itsTEView->GetContext(cJustChange);
-
- this->ICommand(cJustChange, theContext, kCanUndo, kCausesChange, theContext);
- fTEView = itsTEView;
- fOldJust = itsTEView->fJustification;
- fNewJust = itsNewJust;
- } // TJustCommand::IJustCommand
-
- //----------------------------------------------------------------------------------------
- // TJustCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocDoCommand
-
- void TJustCommand::DoIt() // override
- {
- fTEView->SetJustification(fNewJust, kRedraw);
- } // TJustCommand::DoIt
-
- //----------------------------------------------------------------------------------------
- // TJustCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment TEDocDoCommand
-
- void TJustCommand::UndoIt() // override
- {
- fTEView->SetJustification(fOldJust, kRedraw);
- } // TJustCommand::UndoIt
-
- //----------------------------------------------------------------------------------------
- // End of UTEDocument.cp
-
- #pragma segment Inline
-